package com.code.zjm;

import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private final static String TAG = MainActivity.class.getSimpleName();
    private ListView sensorListView;
    private SensorManager sensorManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        sensorListView = (ListView) findViewById(R.id.sensor_list);
        final List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

        sensorListView.setAdapter(new SensorAdapter(this, sensors));

        sensorListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Sensor sensor = sensors.get(position);
                Intent intent = new Intent(MainActivity.this, SensorDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("Name",sensor.getName());
                bundle.putInt("Type",sensor.getType());
                bundle.putFloat("MaxRange",sensor.getMaximumRange());
                bundle.putInt("MinDelay",sensor.getMinDelay());
                bundle.putFloat("Power",sensor.getPower());
                bundle.putFloat("Resolution",sensor.getResolution());
                bundle.putString("Vendor",sensor.getVendor());
                bundle.putInt("Version",sensor.getVersion());
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}
